package com.shilan.administrator.qintfm.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shilan.administrator.qintfm.R;

/**
 * Created by dllo on 16/1/14.
 */
public abstract class BaseFragment extends Fragment {

    private FragmentManager fm;
    private FragmentTransaction ft;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    /**
     * 跳转
     *
     * @param fragment
     */
    public void goToNext(Fragment fragment) {

        fm = getActivity().getSupportFragmentManager();

        ft = fm.beginTransaction();
        ft.setCustomAnimations(
                R.anim.push_left_in,
                R.anim.no_push,
                R.anim.no_push,
                R.anim.push_right_out
        );
        //TODO
        ft.replace(R.id.mainview_framelayout, fragment);
        ft.addToBackStack(null);
        ft.commit();
    }


    /**
     * 返回
     */
    public void goBack() {
        if (fm == null) {
            fm = getFragmentManager();
        }
        fm.popBackStack();
        fm.popBackStackImmediate("", 1);
    }
}
